home *** CD-ROM | disk | FTP | other *** search
/ Amiga Inside! / Amiga FD Inside (1995)(Ultramax).iso / berndspd / sonstiges / lmst / lmst.c < prev    next >
C/C++ Source or Header  |  1993-07-02  |  5KB  |  253 lines

  1. /*
  2. .key file/a
  3. bin/cc <file>.c -a +c +l -l80 +fi -iwork:aztec/include +iwork:aztec/preinclude/include.pre +l -o ram:<file>.asm
  4. bin/as ram:<file>.asm -c -o ram:<file>.o 
  5. bin/ln ram:<file>.o lib/mal32.lib lib/cl32.lib -o <file>
  6. */
  7. #include <exec/types.h>
  8. #include <intuition/intuition.h>
  9. #include <graphics/gfx.h>
  10. #include <graphics/text.h>
  11. #include <time.h>
  12. #include <math.h>
  13.  
  14. #define EOS '\0'
  15.  
  16. extern double atof();
  17.  
  18. double ABS(x)
  19. double x;
  20. {
  21.   if(x<0.0) x=x*-1;
  22.   return x;      
  23. }
  24.  
  25. double FRAC(x)
  26. double x;
  27. {
  28.   x=x-(long)(x);
  29.   if(x<0.0) x++;
  30.   return(x);
  31. }
  32.  
  33. reverse(s)
  34. register char *s;
  35. {
  36.   register int c,i,j;
  37.  
  38.   for(i=0,j=strlen(s)-1; i<j ;i++,j--){
  39.     c=s[i];
  40.     s[i]=s[j];
  41.     s[j]=c;
  42.   }
  43. }
  44.  
  45. ltoa(n,s)
  46. register char s[];
  47. register long n;
  48. {
  49.   register int i=0;
  50.   register int vorzeich=0;
  51.   if(n<0){
  52.     vorzeich=1;
  53.     n=-n;
  54.   }
  55.   do{
  56.     s[i++]=n%10+'0';
  57.   }while((n/=10)>0);
  58.   if(i<2)  s[i++]='0';
  59.   if(vorzeich)
  60.       s[i++]='-';
  61.   s[i]=EOS;
  62.   reverse(s);
  63. }
  64.  
  65.   
  66. /****************************************************/
  67. /* MJD()  Modifiziertes Julianisches Datum          */
  68. /*        ist genau von 1 v.Chr. bis in die Zukunft */
  69. /****************************************************/
  70. double MJD(day,month,year,hour)
  71. int    day,month,year;
  72. double hour;
  73. {
  74.   double a,mjd;
  75.   int    b;
  76.  
  77.   a=10000.0*year+100.0*month+day;
  78.   if(month<=2){
  79.     month=month+12;
  80.     year=year-1;
  81.   }
  82.   if(a<15821004.1)  b=-2+(int)((year+4716)/4)-1179;            
  83.   else              b=(int)(year/400)-(int)(year/100)+(int)(year/4);
  84.   a=365.0*year-679004.0;
  85.   mjd=a+b+(int)(30.6001*(month+1))+day+hour/24.0;
  86.   return(mjd);
  87. }
  88.  
  89. /***********************************************************/
  90. /* LMST()  mittlere Ortssternzeit (Local mean sideral time */
  91. /***********************************************************/
  92. double LMST(mjd,lambda)
  93. double mjd,lambda;
  94. {
  95.   double mjd0,t,ut,gmst,lmst;
  96.  
  97.   mjd0=(long)(mjd);
  98.   ut=(mjd-mjd0)*24.0;
  99.   t=(mjd0-51544.5)/36525.0;
  100.   gmst=6.697374558+1.0027379093*ut
  101.     +(8640184.812866+(0.093104-6.2E-6*t)*t)*t/3600.0;
  102.   lmst=24.0*FRAC((gmst-lambda/15.0)/24.0);
  103.   return(lmst);
  104. }
  105.  
  106.  
  107. /* Deklarationen */
  108. struct Library   *OpenLibrary();
  109. VOID   CloseLibrary();
  110. struct Window    *OpenWindow();
  111.  
  112. /* externe Structuren */
  113. struct IntuitionBase   *IntuitionBase;
  114. struct GfxBase         *GfxBase;
  115. struct IntuiMessage    *msg=NULL;
  116.  
  117. struct RastPort *rp;
  118. struct Window *win;
  119. ULONG  class;
  120. USHORT code;
  121.  
  122. /* Funktionen */
  123.  
  124. SHORT OpenLib()
  125. {
  126.   if(!(IntuitionBase=(struct IntuitionBase *)
  127.     OpenLibrary("intuition.library",0)))    return(1);
  128.   if(!(GfxBase=(struct GfxBase *)
  129.     OpenLibrary("graphics.library",0)))    return(2);
  130.   return(0);
  131. }
  132.  
  133. VOID CloseLib()
  134. {
  135.   if(IntuitionBase)  CloseLibrary(IntuitionBase);
  136.   if(GfxBase)        CloseLibrary(GfxBase);
  137. }
  138.  
  139. struct Window *GetWindow(left,top,width,height,idcmp,flags,title,gad) 
  140.   SHORT  left,top,width,height;
  141.   ULONG  idcmp,flags;
  142.   STRPTR title;
  143.   struct Gadget *gad;
  144. {
  145.   struct NewWindow NW;
  146.   NW.LeftEdge             =left;
  147.   NW.TopEdge              =top;
  148.   NW.Width                =width;
  149.   NW.Height               =height;
  150.   NW.DetailPen=NW.BlockPen=-1;
  151.   NW.IDCMPFlags           =idcmp;
  152.   NW.Flags                =flags;
  153.   NW.FirstGadget          =gad;
  154.   NW.CheckMark            =NULL;
  155.   NW.Title                =title;
  156.   NW.Screen               =NULL;
  157.   NW.BitMap               =NULL;
  158.   NW.MinWidth=NW.MinHeight=10;
  159.   NW.MaxWidth             =640;
  160.   NW.MaxHeight            =256;
  161.   NW.Type                 =WBENCHSCREEN;
  162.   return(OpenWindow(&NW));
  163. }
  164.  
  165. VOID error(fehler)
  166.  STRPTR fehler;
  167. {
  168.   puts("Library Error !");
  169.   if(win)    CloseWindow(win);
  170.   CloseLib();
  171.   exit(0);
  172. }
  173.  
  174. VOID Sternzeit(lambda,l2)
  175. double lambda, l2;
  176. {
  177.   long   t,h,m,s;
  178.   struct tm *tp;
  179.   int    day,month,year;
  180.   double hour,mjd,mjd_ut,std,min,sec;
  181.   char   hh[8], mm[8], ss[8], lmst[32];
  182.   
  183.   time(&t);
  184.   tp=localtime(&t);
  185.   day=tp->tm_mday;  month=1+tp->tm_mon;  year=1900+tp->tm_year;
  186.   h=tp->tm_hour;  m=tp->tm_min;  s=tp->tm_sec;
  187.   hour=h+m/60.0+s/3600.0;
  188.   l2=l2/24.0;
  189.   mjd=MJD(day,month,year,hour);
  190.   mjd_ut=mjd+l2;
  191.   std=LMST(mjd_ut,lambda);
  192.   h=(long)(std);
  193.   min=FRAC(std);       m=(long)(min*60.0);
  194.   sec=FRAC(min*60.0);  s=(long)(sec*60.0);
  195.   ltoa(h,hh);  ltoa(m,mm);  ltoa(s,ss);
  196.   strcpy(lmst," Local mean star time: ");  strcat(lmst,hh);  strcat(lmst,":");
  197.   strcat(lmst,mm);  strcat(lmst,":");  strcat(lmst,ss);  strcat(lmst," ");
  198.   SetAPen(rp,1);
  199.   Move(rp,30,7);
  200.   Text(rp,lmst,32);
  201. }
  202.  
  203. main(argc,argv)
  204. int argc;
  205. char *argv[];
  206. {
  207.   struct tm *tp;
  208.   long   t,m;
  209.   int    ok=0;
  210.   double lambda, l2;
  211.  
  212.   puts("Lmst V2.0 by Th.Hausknecht 1.3.93\n");
  213.  
  214.   if(argc !=3)  puts("error! use:  Lmst [longidute] [timezone]   east-/west+  MEZ = -1 MESZ = -2\n");
  215.   else{
  216.     lambda=atof(argv[1]);
  217.     l2    =atof(argv[2]);
  218.  
  219.     if(OpenLib()){
  220.       error("Libraries");
  221.     }
  222.     if(!(win=GetWindow(0,0,341,10,CLOSEWINDOW | VANILLAKEY | INTUITICKS,
  223.           WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | ACTIVATE, 0,0))){
  224.       error("Window");
  225.     }
  226.  
  227.     rp=win->RPort;
  228.  
  229.     while(ok==0)
  230.     {
  231.       Wait(1 << win->UserPort->mp_SigBit);
  232.       while( msg = (struct IntuiMessage *)GetMsg(win->UserPort) )
  233.       {
  234.         class = msg->Class;
  235.         code  = msg->Code;
  236.         ReplyMsg(msg);
  237.  
  238.         switch(class)
  239.         {
  240.           case CLOSEWINDOW: ok++;
  241.                      break;
  242.  
  243.           case INTUITICKS:  Sternzeit(lambda, l2);
  244.                   break;
  245.         }
  246.       }
  247.     }
  248.     ClearMenuStrip(win);
  249.     CloseWindow(win);
  250.     CloseLib();
  251.   }
  252. }
  253.